A dichotomy color quantization algorithm for the HSI color space

Color quantization is used to obtain an image with the same number of pixels as the original but represented using fewer colors. Most existing color quantization algorithms are based on the Red Green Blue (RGB) color space, and there are few color quantization algorithms for the Hue Saturation Intensity (HSI) color space with a simple uniform quantization algorithm. In this paper, we propose a dichotomy color quantization algorithm for the HSI color space. The proposed color quantization algorithm can display images with a smaller number of colors than other quantization methods of RGB color space. The proposed algorithm has three main steps as follows: first, a single-valued monotonic function of the Hue (H) component in the from RGB color space to HSI color space (RGB-HSI) color space conversion is constructed, which can avoid the partition calculation of the H component in the RGB-HSI color space; second, an iterative quantization algorithm based on the single-valued monotonic function is proposed; and third, a dichotomy quantization algorithm is proposed to improve the iterative quantization algorithm. Both visual and numerical evaluations reveal that the proposed method presents promising quantization results.


Methods
In this section, part A, C, and D are the solutions described corresponds to our contribution, part B is taken from other existing methods. In part A, we map the H component of the HSI color space to a single-valued monotonic function, and then according to the optimized quantization algorithm of part B, we propose an iterative quantization algorithm of part D, and the last we propose a dichotomy quantization algorithm to improve the iterative quantization algorithm. The solution of part D is better than the solution of part C, so we choose dichotomy quantization algorithm of part D to compare with other quantization algorithms.
A. The single-valued monotonic function transformation of the H component.
The model of the HSI color space is shown in Fig. 1 Fig. 2(a). It can be seen from the Fig. 2(a) that the value of H ′ is not discontinuous on the interval [0, 2π) , and the quantization operation cannot be performed for hue component H ′ .
In the RGB color space to HSI color space conversion process, cos (H) cos π 3 − H is used instead of the H component in the S-SC algorithm 26 , and the value range of H ′ is [−1, 2) in sectors [0, 2π 3) , [2π 3, 4π 3) and [4π 3, 2π) . The relationship of H ′ and H component can be expressed in Fig. 2(a), the abscissa represents the H component, and the ordinate represents H ′ . There are three segmented curves in Fig. 2(a), after inverting the three segmented curves and performing the shift operation, we can obtain the curves in Fig. 2(b), i.e., the relationship between f (H) and H is shown in Fig. 2(b), the abscissa still represents the H component, and the ordinate is represented by the function f (H).Therefore, function f (H) can be constructed, and the value ranges of the constructed function for the three sectors are [0, 3) , [3,6) and [6,9) , respectively. Therefore, the value range of function f (H) in the interval [0, 2π) is [0, 9) . Function f (H) is shown as formula (2), and the relationship between f (H) and H is shown in Fig. 2

B. The optimized quantization algorithm. Assuming that the value range of a variable
is the function of variable x , and p(x) is the probability density function of f (x) . The function f (x) is quantized into N levels on the interval [a, b] . The minimum mean square error is used for the criterion, and the optimized quantization can be expressed as follows: where x 0 = a , x N = b and y n is the quantized value of function f (x) in the quantization interval [x n , x n+1 ] . In particular, when variable x obeys an equal probability distribution, Eq. (3) can be reduced to Eq. (4): Clearly, there are N − 1 unknown variables in sequence x 1 , x 2 · · · , x N−1 , there are N unknown variables about y n ,n = 1, 2, · · · , n , and there are 2N − 1 unknown variables in total. When f (x) is a continuous differentiable function, the quantization interval x n and the corresponding quantized value y n can be obtained by calculating the derivative. The derivative of function S 2 to x n is taken, and by setting dS 2 dx n = 0 , we can obtain: In Eq. (5), the value range of n is n = 0, 1, 2 · · · , N − 2 , and there are N − 1 equations in Eq. (4). The derivative of function S 2 to y n is taken, and by setting dS 2 dy n = 0 , we can obtain: Formula (6) can be transformed into: It can be seen from Eq. (7) that the quantized value y n is the median value of function f (x) in the interval [x n , x n+1 ] , and the value range of n is [0, N − 1] of y n , so there are N equations in Eq. (7). In summary, there are 2N − 1 unknown variables in Eqs. (5) and (7), and the number of equations is also 2N − 1 , so the solution to the equation is unique. Substituting Eq. (7) into Eq. (5), we can obtain: www.nature.com/scientificreports/ where n = 0, 1, 2 · · · , N − 1.
When x n−1 , x n are known, Eq. (9) can be transformed into: where K is a variable. To calculate x n+1 , we can establish the equation: x−x n . Here, t is only a variable, and the value range of t is between x and x n . Equation (9) can be expressed as: when f (x) is a monotonically increasing function, if the solution to Eq. (11) exists in the domain, then the solution is unique, the proof is shown in Online Supplementary Information. Therefore, we can quantize function f (x) . That is, we can quantize function f (H).
C. Iterative quantization algorithm. The variable K can be calculated using Eq. (10), and the iterative problem can be equivalent to a minimum value solution problem: Therefore, the solution to x in formula (12) is x n+1 , and the solution to formula (12) is the solution to formula (13): Intuitively, the quantization point is selected in the interval [0, 2π ] because the value of the H component is [0, 2π ] . First, the initial value of the quantization interval is x n−1 = x 0 = 0 , x n = 0 , x n+1 = 2π , n = 1 , and a min = max(f (H)) ; second, the point x that meets the conditions of formula (12) in the quantization interval [0, 2π ] is found, and the value a min = a is replaced by x n+1 = x ; third, x = x + ; the second step is repeated until x >= 2π , then the next quantization point x n+1 is found; fourth, the starting value of quantization interval is updated, x = x n+1 + , x n−1 = x n , x n = x n+1 , x n = x n+1 , and a min = max(f (H)) . The process continues to find the next quantization point x n+1 in the interval [x, 2π ] . The iterative process algorithm is as follows: For a given value x 1 , the next quantization point x 2 is calculated using the iterative algorithm, and the number of searches required by the algorithm is (2π − x 1 ) � . Similarly, when quantization point x n+1 is found, the number of searches required by the algorithm is (2π − x n ) � . Therefore, the number of searches required by (2π − x n )/� . When x 1 is changed, the above process must be repeated.

D. Dichotomy quantization algorithm.
The complexity of the above iterative algorithm is affected by the parameter . If the algorithm accuracy is high, the value of should be small; otherwise, it will lead to a large amount of calculation. However, if the algorithm accuracy is low, the calculated quantization points are not good enough, and it will even cause greater errors in subsequent iterations. To solve the contradiction between the accuracy and the calculation error caused by the parameter , it is necessary to further study a more effective algorithm solution. So, we propose another dichotomy quantization algorithm. We create the equation: Clearly, the function Y (x) is a monotonically increasing function. The derivative is taken on both sides of Eq. (14), and the equation can be expressed as Y .
Because the function is a monotonically increasing function, the extreme value problem of formula (14) can be transformed into a problem of solving the equation (13), we can obtain: The dichotomy quantization algorithm can be used to find the quantization points x n+1 , n = 1, 2 · · · , N − 1 on the interval [x 1 , 2π ] , and the process of dichotomy quantization is as follows: The HSI color quantization algorithm. Quantize a color image in the HSI color space. According to the R, G and B components of an input RGB image, the color quantization process for the HSI color space is as follows. First, construct the H component's function f (H) using the single-valued monotonic function transformation of the H component algorithm proposed of section "Methods-A". Second, calculate the quantization point x n using the dichotomy quantization algorithm of dichotomy quantization algorithm of Section "Methods-D". Third, obtain the quantization value y n of function f (H) in each quantization point, n = 0, 1, 2, ..., N − 1 , N represents the number of quantization points in the color space, n represents the variable the number of quantization points, using Eq. (7) with quantization point x n . The quantization value y n is reshaped as follows: Here, Z n is an unsigned integer, and is the value of the H component in the HSI space, y n is the value of a quantized point corresponding to function f (H) , M is a positive integer, ⌊ ⌋ rounds down, the number 9 is the absolute value of the value range of the function, and the number 0.5 is convenient for the subsequent experimental operation.
The calculation method for the S and I components in the HSI space is consistent with the S-SC algorithm 26 , and the S and I components are normalized before quantization. The quantization value is consistent with the quantization result of the H component; that is, the quantization table of the H component is used as the quantization table of the S and I components.
Generation of an RGB image. The reconstructed RGB image is obtained using formulas (17)- (19), and Z n needs to be inverted and shifted. This operation is equivalent to returning the N-level quantized value back to the H ′ transformation scale 26 . www.nature.com/scientificreports/ When Z n ∈ [0, 3) , it is equivalent to H ∈ 0, 2π 3 , and the R, G, and B components of the quantized image are as follows: (b) When Z n ∈ [3,6) , it is equivalent to H ∈ 2π 3, 4π 3 , and the R, G, and B components of the quantized image are as follows: (c) When Z n ∈ [6,9) , it is equivalent to H ∈ 4π 3, 2π , and the R, G, and B components of the quantized image are as follows:

Results
In this section, we first provide a detailed description of the dataset and the experimental environment. Then we provide the results of the effect of different parameters. At last, we provide the results of quantization images with the proposed dichotomy quantization algorithm, which is compared with other quantization algorithms. Quantization analysis. The initial value x 1 is necessary for the calculation of the quantization point. The parameters , σ , N, and x 1 greatly influence the quantization results, so we analyze the effect of these parameters.
Effect of the N and x 1 parameters. The quantization points are calculated by the iterative algorithm, and the number of quantization points N is affected by the iteration step size and the initial value of the quantization point x 1 . The simulation results show that when the iteration step is constant ( < x 1 , where is a sufficiently small number), the larger the value of x 1 is, the smaller the number of quantization points N, and the smaller the value of x 1 is, the greater the number of quantization points N. When x 1 changes within a certain range, the quantization number N does not change much, but if the value of x 1 is greater than a certain value or less than a certain value, the value range of N changes greatly. Taking a value range of x 1 from 0.01 to 0.1 as an example, the value of is 0.0001, and the value of σ is 0.0001. The relationship between x 1 and N is shown in Table 1. When the value range of x 1 is 0.03 to 0.1, x 1 is decreasing, and the value of N gradually increases and when the value range of x 1 is less than 0. 03, the value of N increases and changes greatly.
The quantization points are calculated using the dichotomy algorithm, and the number of quantization intervals N is affected by the termination condition and the initial value of the quantization point x 1 . To verify the performance of the dichotomy method, the relationship between x 1 and the number of quantization points N and the relationship between the value of the termination condition σ and the quantization number N are simulated. The results show that the value of x 1 affects the size of the number of quantization points N. In general, the larger the value of x 1 is, the smaller the number of quantization points N and the smaller the value of x 1 is, the greater the number of quantization points N. When x 1 changes within a certain range, the quantization interval value N does not change much, but if x 1 is greater than a certain value or less than a certain value, the value range of N changes greatly. Taking a value range of x 1 from 0.01 to 0.1 as an example, the relationship between x 1 and the quantization point N is shown in Table 1. When the value of x 1 is between 0.03 and 0.1, the value of N increases and changes little and when the value is less than 0.03, the value of N increases and changes greatly.
Effect of the , σ , and N parameters. While the quantization points are calculated using the iterative algorithm, the quantization step size also affects the value of the quantization points number N. When the value of x 1 is   1 0.05 0.04 0.03 0.02 0.15  www.nature.com/scientificreports/ constant, and the step size is less than x 1 , the value of the step size has little effect on the number of quantization points N. As the step size changes, the number of quantization points N fluctuates in a certain range, but the range is not large. Taking x 1 = 0.05 as an example, the result is shown in Fig. 3, the step size ranges from 0.01 to 0.001, and the number of quantization points N fluctuates near. In practical applications, when N is a specific value, x 1 and must be selected appropriately. When the quantization point is calculated using the dichotomy method, the value of the termination condition σ will also affect the value of N to a certain extent. When the value of x 1 is constant and the termination condition σ changes within a certain range ( σ is small enough), the value of N does not change much; however, if the termination condition σ is greater than a certain value or less than a certain value, the value range of N changes greatly. Taking the value of x 1 as 0.05 as an example, the result is shown in Fig. 4. The termination condition σ for calculating the quantization point varies between 0.002 and 0.009, and the value of N does not change much. When σ is set to 0.01, the number of quantization intervals N has a relatively large change. In practical applications, when N is a specific value, x 1 and σ must be selected appropriately.
Effect of the x 1 parameter. Previous section specifies that the number of searches required by the iterative algorithm is (2π − x n )/� , and the number of algorithm searches is related to the iteration step size. However, the number of searches required to quantize using the dichotomy method is lower. We use the iterative and dichotomy algorithms to quantize the interval [0, 2π) , and the simulation results of the number of iterations are   Table 2. When the value of x 1 is the same, the number of iterations of the dichotomy algorithm is much less than that of the iterative algorithm, and the precision value is 0.0001. Therefore, the dichotomy algorithm is less complex than the iterative algorithm.
Quantization simulation results. We use the dichotomy algorithm to quantize color image. After many experiments, the value of x 1 is set to 0.01, and σ is set to 0.001. Taking the Mandrill picture as an example, the Mandrill image is published under the CC-BY open access license. For different quantization points, the quantized HSI image and the reconstructed RGB image are shown in Fig. 5, there are obvious differences at different quantization points. When the number of quantized colors is smaller, the distortion of the HSI image is more obvious; when the number of quantized colors is different, the quality of the reconstructed image is different. When the value of N is 128, the reconstructed RGB image is very close to the original image. Compared with the original image, the MSE value of Mandrill picture is as low as 2.75, and the results are recorded in Table 3. With the gradual increase in the value of N, the reconstructed RGB image gradually becomes similar to the original image. When the value of N reaches 128, the reconstructed RGB image is very close to the original RGB image.

Comparison with other color quantization methods. Comparison with other HSI quantization al-
gorithms. There are few HSI quantization methods, the quantization methods are based on uniform quantization. For example, in literature 28 , the H component is quantized into 7 quantization points, and the S and I components are quantized into 3 quantization points. Moreover, the purpose of these few HSI quantization algorithms is not color quantization; that is, quantized color images cannot be obtained. Therefore, to verify the performance of each algorithm, we use a uniform quantization algorithm to compare the dichotomy algorithm using the PSNR 27 Fig. 6. When the value of N is the same, the PSNR value of the dichotomy algorithm is higher than that of the uniform method. This is the reason why we choose the dichotomy algorithm to determine the quantization points in this paper.
Comparison with other RGB quantization algorithms. Since there are few image quantization algorithms in HSI color space, in order to prove the effect of our proposed quantization , we transfer the images quantized in HSI color space to RGB color space, and to compared with RGB images which are quantization by other RGB color quantization methods. In this part, the images used for test are commonly used to test color quantification methods 29 , they are all the same dimensions of 512 × 512, the test images include Mandrill, Plane, Lake, Peppers. To compare the performance with other RGB quantization s, the number of quantization points N is set to a fixed number. Additionally, we take N as one of the conditions for the termination of the dichotomy quantization algorithm. The images are  Table 3. We choose the ATCQ 16 , PSO + KM 12 , ABC + KM 12 , SFLA-CQ 12 to comparison, the reasons are as follows: one is that the three methods ATCQ, PSO + KM, and ABC + KM are well-known color image quantization methods and other quantization algorithms often compare with, the other is that the size of the test images of these methods is pointed out in the references 12 , compared with the number of quantization points of other quantization articles. The number of quantization points of the references 12 is relatively rich. In addition, the SFLA-CQ in the references 12 was published in 2019, which was relatively new in the color quantization algorithm. The MSE of the comparison RGB quantization algorithms are copied from the Tables 3 and 5 of the cited article 12 , the values of MSE are the minimum values in the different quantization points for quantizations.
The compared results are recorded in Table 3, It can be seen from the table that when the color quantization point of our proposed is 32, the MSE of Mandell image of the proposed algorithm has been as low as 43.9, however, the MSE values of ATCQ, PSO + KM, ABC + KM and SFLA-CQ are 758.39, 373.32,373.66, 416.42, of all the other four RGB quantization methods; When the quantization point is 64,128 and 256, the MSE of Mandell image has been as low as 11.19, 2.75 and 0.69 respectively. The MSE of Mandell image of the proposed HSI quantization algorithm is much lower than that of other methods based on RGB color space quantization algorithms. Similarly, the same lower MSE results are obtained in the test of the pictures Plane, Lake and Peppers than other compared quantization points in the quantization points 32, 64, 128 and 256.
It is worth emphasizing that the advantage of this proposed quantization algorithm provides a new idea for color quantization methods, which can be used by researchers in HSI color space.

Conclusion
In this paper, we propose a new color quantization algorithm for the HSI color space. First, to construct a singlevalued monotonic function of the H component, the sector information of the H component is removed. Then, based on the analysis of this function, we propose an iterative quantization algorithm, which can calculate the next quantization point from the obtained quantization points. The iterative quantization algorithm is improved using a dichotomy algorithm, which can effectively reduce the complexity of the iterative algorithm. The simulation results show that the quality of the reconstructed RGB image using the dichotomy color quantization algorithm is good for randomly selected images. The speed of the proposed quantization speed is insufficient, in the follow-up work, we will study the speed of quantifying the H component to improve the efficiency of the algorithm.